/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package packForm.Cadastros;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Blob;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import packDatabase.DaoAcess;
import packForm.Padroes.FrmPesquisar;

/**
 *
 * @author everaldo
 */
public class FrmCadProdutos extends javax.swing.JInternalFrame {
    private DaoAcess conexao = new DaoAcess();
    private String local=null;
    /**
     * Creates new form frmCadProdutos
     */
    public FrmCadProdutos() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnSalvar = new javax.swing.JButton();
        btnNovo = new javax.swing.JButton();
        btnProcurar = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        txtCodigo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtSubgrupo = new javax.swing.JTextField();
        btnPesquisarSubgrupo = new javax.swing.JButton();
        txtCodSubgrupo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        spnTipo = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        txtGrupo = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tabIngredientes = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        tabExtras = new javax.swing.JTable();
        txtDesIngredientes = new javax.swing.JTextField();
        btnPesuisaIngredientes = new javax.swing.JButton();
        txtCodIngredientes = new javax.swing.JTextField();
        txtDesExtras = new javax.swing.JTextField();
        btnPesquisarExtras = new javax.swing.JButton();
        txtCodExtras = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtDescricao = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        txtCaminhoFoto = new javax.swing.JTextField();
        btnPesquisaFoto = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        btnAdicionarIngre = new javax.swing.JButton();
        btnRemoverIngre = new javax.swing.JButton();
        btnAdicionarExtras = new javax.swing.JButton();
        btnRemoverExtras = new javax.swing.JButton();
        txtNomeProduto = new javax.swing.JTextField();
        txtPreco = new javax.swing.JFormattedTextField();
        txtTempo = new javax.swing.JFormattedTextField();
        btnVizualizarImagem = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnSalvar.setText("Salvar");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        btnNovo.setText("Novo");
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });

        btnProcurar.setText("Procurar");
        btnProcurar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProcurarActionPerformed(evt);
            }
        });

        btnExcluir.setText("Excluir");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnProcurar, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSalvar)
                    .addComponent(btnNovo)
                    .addComponent(btnProcurar)
                    .addComponent(btnExcluir))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        txtCodigo.setEditable(false);

        jLabel1.setText("Código:");

        jLabel2.setText("Nome:");

        txtSubgrupo.setEditable(false);

        btnPesquisarSubgrupo.setText("...");
        btnPesquisarSubgrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarSubgrupoActionPerformed(evt);
            }
        });

        txtCodSubgrupo.setEditable(false);

        jLabel3.setText("Subgrupo:");

        jLabel4.setText("Preço:");

        spnTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Produto", "Ingrediente", "Extra" }));
        spnTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spnTipoActionPerformed(evt);
            }
        });

        jLabel5.setText("Tipo:");

        txtGrupo.setEditable(false);

        jLabel6.setText("Grupo:");

        jLabel7.setText("Tempo médio:");

        tabIngredientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Ingrediente"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(tabIngredientes);

        tabExtras.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Extra"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(tabExtras);

        txtDesIngredientes.setEditable(false);

        btnPesuisaIngredientes.setText("...");
        btnPesuisaIngredientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesuisaIngredientesActionPerformed(evt);
            }
        });

        txtCodIngredientes.setEditable(false);

        txtDesExtras.setEditable(false);

        btnPesquisarExtras.setText("...");
        btnPesquisarExtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarExtrasActionPerformed(evt);
            }
        });

        txtCodExtras.setEditable(false);

        jLabel8.setText("Ingredientes:");

        jLabel9.setText("Extras:");

        txtDescricao.setColumns(20);
        txtDescricao.setRows(5);
        jScrollPane1.setViewportView(txtDescricao);

        jLabel10.setText("Descrição:");

        txtCaminhoFoto.setEditable(false);

        btnPesquisaFoto.setText("...");
        btnPesquisaFoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisaFotoActionPerformed(evt);
            }
        });

        jLabel12.setText("Foto:");

        btnAdicionarIngre.setFont(new java.awt.Font("Ubuntu", 0, 9)); // NOI18N
        btnAdicionarIngre.setText("+");
        btnAdicionarIngre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarIngreActionPerformed(evt);
            }
        });

        btnRemoverIngre.setFont(new java.awt.Font("Ubuntu", 0, 9)); // NOI18N
        btnRemoverIngre.setText("-");
        btnRemoverIngre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverIngreActionPerformed(evt);
            }
        });

        btnAdicionarExtras.setFont(new java.awt.Font("Ubuntu", 0, 9)); // NOI18N
        btnAdicionarExtras.setText("+");
        btnAdicionarExtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarExtrasActionPerformed(evt);
            }
        });

        btnRemoverExtras.setFont(new java.awt.Font("Ubuntu", 0, 9)); // NOI18N
        btnRemoverExtras.setText("-");
        btnRemoverExtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverExtrasActionPerformed(evt);
            }
        });

        txtPreco.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));

        txtTempo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));

        btnVizualizarImagem.setText("Visualizar Imagem");
        btnVizualizarImagem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVizualizarImagemActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        jLabel11.setText("Informe as caracteriscas do produto que apareceram no app. ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(txtCodSubgrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnPesquisarSubgrupo)
                                .addGap(9, 9, 9)
                                .addComponent(txtSubgrupo))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(txtCodIngredientes, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnPesuisaIngredientes)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtDesIngredientes)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnAdicionarIngre, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnRemoverIngre, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel6)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                    .addComponent(txtCodExtras, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(btnPesquisarExtras)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(txtDesExtras, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(btnAdicionarExtras, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(btnRemoverExtras, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(txtGrupo)
                                    .addGap(2, 2, 2)))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtCodigo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(txtNomeProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(txtPreco, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(txtTempo, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(spnTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(btnPesquisaFoto)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtCaminhoFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addComponent(btnVizualizarImagem, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnPesquisaFoto, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtCaminhoFoto, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNomeProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtPreco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addGap(30, 30, 30))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(jLabel7))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(spnTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(txtTempo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtSubgrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCodSubgrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnPesquisarSubgrupo)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnVizualizarImagem))))
                .addGap(31, 31, 31)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDesIngredientes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCodIngredientes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPesuisaIngredientes)
                    .addComponent(txtDesExtras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCodExtras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPesquisarExtras)
                    .addComponent(btnAdicionarIngre)
                    .addComponent(btnRemoverIngre)
                    .addComponent(btnAdicionarExtras)
                    .addComponent(btnRemoverExtras)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnPesquisaFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisaFotoActionPerformed
       if(!txtCodigo.getText().equals("")){
            JFileChooser fileChooser = new JFileChooser();  
            fileChooser.setDialogTitle("Importar imagem");  
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            if (fileChooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION){
                local = fileChooser.getSelectedFile().getPath();
                txtCaminhoFoto.setText(local);
                
            }
        }else{
            JOptionPane.showMessageDialog(null, "Selecione um produto.\nCaso seja um novo cadastro salve-o primeiramente!", "Atenção",0);
        } 
    }//GEN-LAST:event_btnPesquisaFotoActionPerformed

    private void btnPesquisarExtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarExtrasActionPerformed
        FrmPesquisar pesquisar = new FrmPesquisar(null,true,"CODPRODUTO AS 'Código', PRODUTO AS 'Nome', CARACTERISTICAS AS 'Caracteristicas',PRECO as 'Preço', TIPO as 'Tipo'","TAB_PRODUTOS","","");
        pesquisar.comboPesquisa.addItem("CodProduto");
        pesquisar.comboPesquisa.addItem("Produto");
        pesquisar.comboPesquisa.addItem("Caracteristicas");
        pesquisar.setVisible(true);
        if (pesquisar.dados.size()!=0){
            txtCodExtras.setText(pesquisar.dados.get(0));
            txtDesExtras.setText(pesquisar.dados.get(2));
        }
    }//GEN-LAST:event_btnPesquisarExtrasActionPerformed

    private void btnPesuisaIngredientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesuisaIngredientesActionPerformed
        FrmPesquisar pesquisar = new FrmPesquisar(null,true,"CODPRODUTO AS 'Código', PRODUTO AS 'Nome', CARACTERISTICAS AS 'Caracteristicas',PRECO as 'Preço', TIPO as 'Tipo'","TAB_PRODUTOS","","");
        pesquisar.comboPesquisa.addItem("CodProduto");
        pesquisar.comboPesquisa.addItem("Produto");
        pesquisar.comboPesquisa.addItem("Caracteristicas");
        pesquisar.setVisible(true);
        if (pesquisar.dados.size()!=0){
            txtCodIngredientes.setText(pesquisar.dados.get(0));
            txtDesIngredientes.setText(pesquisar.dados.get(2));
        }
    }//GEN-LAST:event_btnPesuisaIngredientesActionPerformed

    private void btnPesquisarSubgrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarSubgrupoActionPerformed
        FrmPesquisar pesquisa = new FrmPesquisar(null,true,"CODSUBGRUPO AS 'Codigo', CODGRUPO AS 'Cod. Subgrupo', SUBGRUPO AS 'Descrição'","TAB_SUBGRUPOS","","");
        pesquisa.comboPesquisa.addItem("CodSubGrupo");
        pesquisa.comboPesquisa.addItem("CodGrupo");
        pesquisa.comboPesquisa.addItem("SubGrupo");
        pesquisa.setVisible(true);
        if(pesquisa.dados.size()!=0){
            txtCodSubgrupo.setText(pesquisa.dados.get(0));
            txtSubgrupo.setText(pesquisa.dados.get(2));
            conexao.OpenConect();
            conexao.Select("SELECT GRUPO FROM TAB_GRUPOS WHERE CODGRUPO="+pesquisa.dados.get(1));
            try {
                conexao.rs.first();
                txtGrupo.setText(conexao.rs.getString("GRUPO"));
            } catch (SQLException ex) {
            }
        }
    }//GEN-LAST:event_btnPesquisarSubgrupoActionPerformed

    private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
        limparTela();
    }//GEN-LAST:event_btnNovoActionPerformed

    private void btnProcurarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProcurarActionPerformed
        FrmPesquisar pesquisar = new FrmPesquisar(null,true,"CODPRODUTO AS 'Código', PRODUTO AS 'Nome', CARACTERISTICAS AS 'Caracteristicas',PRECO as 'Preço', TIPO as 'Tipo'","TAB_PRODUTOS","","");
        pesquisar.comboPesquisa.addItem("CodProduto");
        pesquisar.comboPesquisa.addItem("Produto");
        pesquisar.comboPesquisa.addItem("Caracteristicas");
        pesquisar.setVisible(true);
        if (pesquisar.dados.size()!=0){
            //CARREGANDO OS DADOS PRINCIPAIS DA TELA:
            limparTabela(tabIngredientes);
            limparTabela(tabExtras);
            txtCodigo.setText(pesquisar.dados.get(0));
            txtNomeProduto.setText(pesquisar.dados.get(2));
            txtPreco.setText(pesquisar.dados.get(5));
            txtTempo.setText(pesquisar.dados.get(3));
            txtDescricao.setText(pesquisar.dados.get(4));
            txtCodSubgrupo.setText(pesquisar.dados.get(1));
            txtCaminhoFoto.setText(pesquisar.dados.get(8));
            if (pesquisar.dados.get(6).toString().equals("1")){
                spnTipo.setSelectedItem("Produto");
            }else if (pesquisar.dados.get(6).toString().equals("2")){
                spnTipo.setSelectedItem("Ingrediente");
            }else if(pesquisar.dados.get(6).toString().equals("3")){
                spnTipo.setSelectedItem("Extra");
            }
            //CARREGANDO AS DESCRIÇÕES DO GRUPO E SUBGRUPO:
            conexao.OpenConect();
            conexao.Select("SELECT TAB_SUBGRUPOS.SUBGRUPO, TAB_GRUPOS.GRUPO FROM TAB_SUBGRUPOS " +
                           "INNER JOIN TAB_GRUPOS ON (TAB_GRUPOS.CODGRUPO=TAB_SUBGRUPOS.CODGRUPO) " +
                           "INNER JOIN TAB_PRODUTOS ON (TAB_PRODUTOS.CODSUBGRUPO=TAB_SUBGRUPOS.CODSUBGRUPO) " +
                           "WHERE TAB_PRODUTOS.CODPRODUTO="+pesquisar.dados.get(0));
            try {
                conexao.rs.first();
                txtSubgrupo.setText(conexao.rs.getString("TAB_SUBGRUPOS.SUBGRUPO"));
                txtGrupo.setText(conexao.rs.getString("TAB_GRUPOS.GRUPO"));
            } catch (SQLException ex) { 
                System.out.println("Erro: "+ex.getMessage());
            } 
            //CARREGANDO OS INGREDIENTES:
            conexao.Select("SELECT TAB_PRODUTOINGREDIENTES.CODINGREDIENTE,TAB_PRODUTOS.PRODUTO " +
                            "FROM TAB_PRODUTOS " +
                            "INNER JOIN TAB_PRODUTOINGREDIENTES ON (TAB_PRODUTOINGREDIENTES.CODINGREDIENTE=TAB_PRODUTOS.CODPRODUTO) " +
                            "WHERE TAB_PRODUTOINGREDIENTES.CODPRODUTO="+txtCodigo.getText());
            try {
                conexao.rs.beforeFirst();
                DefaultTableModel ingredientes = (DefaultTableModel) tabIngredientes.getModel();
                while(conexao.rs.next()){
                    ingredientes.addRow(new String [] {conexao.rs.getString("TAB_PRODUTOINGREDIENTES.CODINGREDIENTE"),conexao.rs.getString("TAB_PRODUTOS.PRODUTO")});
                }
            } catch (SQLException ex) {
                System.out.println("Erro: "+ex.getMessage());
            }
            //CARREGANDO OS EXTRAS:
            conexao.Select("SELECT TAB_PRODUTOEXTRAS.CODEXTRAS,TAB_PRODUTOS.PRODUTO " +
                           "FROM TAB_PRODUTOS " +
                           "INNER JOIN TAB_PRODUTOEXTRAS ON (TAB_PRODUTOEXTRAS.CODEXTRAS=TAB_PRODUTOS.CODPRODUTO) " +
                           "WHERE TAB_PRODUTOEXTRAS.CODPRODUTO="+txtCodigo.getText());
            try{
                conexao.rs.beforeFirst();
                    DefaultTableModel extras = (DefaultTableModel) tabExtras.getModel();
                while(conexao.rs.next()){
                    extras.addRow(new String [] {conexao.rs.getString("TAB_PRODUTOEXTRAS.CODEXTRAS"),conexao.rs.getString("TAB_PRODUTOS.PRODUTO")});
                }
            } catch (SQLException ex) {
                System.out.println("Erro: "+ex.getMessage());
            }
            conexao.CloseConect();
        }
    }//GEN-LAST:event_btnProcurarActionPerformed

    private void btnAdicionarIngreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarIngreActionPerformed
        if(!txtCodIngredientes.getText().equals("") && !txtCodIngredientes.getText().equals("") && !txtCodigo.getText().equals("")){
            boolean achou=false;
            if (tabIngredientes.getRowCount()!=0){
                for (int i=0;i<tabIngredientes.getRowCount();i++){
                    if (tabIngredientes.getValueAt(i, 0).equals(txtCodIngredientes.getText())){
                        achou=true;
                    }
                }
                if (achou==true){
                    JOptionPane.showMessageDialog(null, "Não é possivel incluir o mesmo ingrediente duas vezes!", "Atenção!", 0);
                }
            }
            if(achou==false){
                DefaultTableModel modelo = (DefaultTableModel) tabIngredientes.getModel();
                modelo.addRow(new String [] {txtCodIngredientes.getText(),txtDesIngredientes.getText()});
                if (!(txtCodIngredientes.getText().equals(""))){
                    conexao.OpenConect();
                    conexao.Insert("INSERT INTO TAB_PRODUTOINGREDIENTES(CODPRODUTO,CODINGREDIENTE) VALUES("+txtCodigo.getText()+","+txtCodIngredientes.getText()+")");
                    conexao.CloseConect(); 
                }
            }        
            txtCodIngredientes.setText("");
            txtDesIngredientes.setText("");

        }else{
            JOptionPane.showMessageDialog(null, "Informe o produto.\nSe for um novo cadastro salve o produto antes!", "Atenção",0);
        }
    }//GEN-LAST:event_btnAdicionarIngreActionPerformed

    private void btnAdicionarExtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarExtrasActionPerformed
        if(!txtCodExtras.getText().equals("") && !txtCodExtras.getText().equals("") && !txtCodigo.getText().equals("")){
            boolean achou=false;
            if (tabExtras.getRowCount()!=0){
                for (int i=0;i<tabExtras.getRowCount();i++){
                    if (tabExtras.getValueAt(i, 0).equals(txtCodExtras.getText())){
                        achou=true;
                    }
                }
                if (achou==true){
                    JOptionPane.showMessageDialog(null, "Não é possivel incluir o mesmo extra duas vezes!", "Atenção!", 0);
                }
            }
            if(achou==false){
                DefaultTableModel modelo = (DefaultTableModel) tabExtras.getModel();
                modelo.addRow(new String [] {txtCodExtras.getText(),txtDesExtras.getText()});
                if (!(txtCodExtras.getText().equals(""))){
                    conexao.OpenConect();
                    conexao.Insert("INSERT INTO TAB_PRODUTOEXTRAS(CODPRODUTO,CODEXTRAS) VALUES("+txtCodigo.getText()+","+txtCodExtras.getText()+")");
                    conexao.CloseConect(); 
                }
            }        
            txtCodExtras.setText("");
            txtDesExtras.setText("");

        }else{
            JOptionPane.showMessageDialog(null, "Informe o produto.\nSe for um novo cadastro salve o produto antes!", "Atenção",0);
        }
    }//GEN-LAST:event_btnAdicionarExtrasActionPerformed

    private void btnRemoverIngreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverIngreActionPerformed
        if (tabIngredientes.getRowCount()!=0){    
            if(!txtCodigo.getText().equals("")){
               conexao.OpenConect();
               int selecao,cod=0;
               selecao=tabIngredientes.getSelectedRow();
               conexao.Select("SELECT CODPRODUTOINGREDIENTE FROM TAB_PRODUTOINGREDIENTES WHERE CODPRODUTO="+txtCodigo.getText()+" AND CODINGREDIENTE="+tabIngredientes.getValueAt(selecao, 0));
               try {
                   conexao.rs.first();
                   cod=conexao.rs.getInt("CODPRODUTOINGREDIENTE");
               } catch (SQLException ex) {
                   System.out.print("Erro: "+ex.getMessage());
               }
               conexao.Delete("DELETE FROM TAB_PRODUTOINGREDIENTES WHERE CODPRODUTOINGREDIENTE="+cod);
               conexao.CloseConect();
               ((DefaultTableModel) tabIngredientes.getModel()).removeRow(tabIngredientes.getSelectedRow());
           }else{
               JOptionPane.showMessageDialog(null, "Informe o ingrediente!", "Atenção",0);            
           }
        }else{
            JOptionPane.showMessageDialog(null, "Não há ingredientes para remover!", "Atenção",0);            
        }
    }//GEN-LAST:event_btnRemoverIngreActionPerformed

    private void btnRemoverExtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverExtrasActionPerformed
        if (tabExtras.getRowCount()!=0){
            if(!txtCodigo.getText().equals("")){
                conexao.OpenConect();
                int selecao,cod=0;
                selecao=tabExtras.getSelectedRow();
                conexao.Select("SELECT CODPRODUTOEXTRAS FROM TAB_PRODUTOEXTRAS WHERE CODPRODUTO="+txtCodigo.getText()+" AND CODEXTRAS="+tabExtras.getValueAt(selecao, 0));
                try {
                    conexao.rs.first();
                    cod=conexao.rs.getInt("CODPRODUTOEXTRAS");
                } catch (SQLException ex) {
                    System.out.print("Erro: "+ex.getMessage());
                }
                conexao.Delete("DELETE FROM TAB_PRODUTOEXTRAS WHERE CODPRODUTOEXTRAS="+cod);
                conexao.CloseConect();
                ((DefaultTableModel) tabExtras.getModel()).removeRow(tabExtras.getSelectedRow());
            }else{
                JOptionPane.showMessageDialog(null, "Informe o extra!", "Atenção",0);            
            }
        }else{
                 JOptionPane.showMessageDialog(null, "Não há extra para remover!", "Atenção",0);              
        }
    }//GEN-LAST:event_btnRemoverExtrasActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        if(txtNomeProduto.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Informe o nome do produto!", "Atenção!", 0);

        }else if(txtPreco.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Informe o preço do produto!", "Atenção!", 0);

        }else if(txtTempo.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Informe o tempo do produto!", "Atenção!", 0);

        }else if(txtCodSubgrupo.getText().equals("")){    
            JOptionPane.showMessageDialog(null, "Informe o subgrupo do produto!", "Atenção!", 0);
        }else{
            conexao.OpenConect();
            int tipo=0;
            if(spnTipo.getSelectedItem().toString().equals("Produto")){
                tipo=1;
            }else if(spnTipo.getSelectedItem().toString().equals("Ingrediente")){
                tipo=2;
            }else if(spnTipo.getSelectedItem().toString().equals("Extra")){
                tipo=3;
            }
            if(txtCodigo.getText().equals("")){//Insert
                try{
                    conexao.Insert("INSERT INTO TAB_PRODUTOS(CODSUBGRUPO,PRODUTO,TEMPOPREPARO,CARACTERISTICAS,PRECO,TIPO) "
                            + "VALUES("+txtCodSubgrupo.getText()+",'"+txtNomeProduto.getText()+"','"+txtTempo.getText()+"',"
                            + "'"+txtDescricao.getText()+"','"+txtPreco.getText().replace(",", ".")+"',"+tipo+")");
                    conexao.Select("SELECT CODPRODUTO FROM TAB_PRODUTOS ORDER BY CODPRODUTO DESC LIMIT 1 ");
                    conexao.rs.first();
                    txtCodigo.setText(conexao.rs.getString("CODPRODUTO"));
                    
                }catch(SQLException e){
                    System.out.println(e.getMessage());
                }
                JOptionPane.showMessageDialog(null, "Produto cadastrado com sucesso!", "Atenção!", 1);
            }else{//update
                conexao.Update("UPDATE TAB_PRODUTOS SET "
                                + "CODSUBGRUPO="+txtCodSubgrupo.getText()+","
                                + "PRODUTO='"+txtNomeProduto.getText()+"',"
                                + "TEMPOPREPARO='"+txtTempo.getText()+"',"
                                + "CARACTERISTICAS='"+txtDescricao.getText()+"',"
                                + "PRECO='"+txtPreco.getText().replace(",", ".")+"',"
                                + "TIPO="+tipo+" "
                            + "WHERE CODPRODUTO="+txtCodigo.getText());
                
                //Gravando Foto:
                if (!txtCaminhoFoto.getText().equals("")){
                    File arquivo = new File(local);
                    FileInputStream inputStream;
                    try {
                        inputStream = new FileInputStream(arquivo); 
                        PreparedStatement pstmt  = conexao.getConnection().prepareStatement("UPDATE TAB_PRODUTOS SET FOTO=?,FOTOCAMINHO=? WHERE CODPRODUTO=?");
                        pstmt.setBinaryStream(1, inputStream,(int)arquivo.length());
                        pstmt.setString(2,txtCaminhoFoto.getText());
                        pstmt.setString(3, txtCodigo.getText());
                        pstmt.execute();  
                    } catch (FileNotFoundException ex) {
                        Logger.getLogger(FrmCadProdutos.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (SQLException ex) {
                        Logger.getLogger(FrmCadProdutos.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                limparTela();
                JOptionPane.showMessageDialog(null, "Produto atualizado com sucesso!", "Atenção!", 1);
            }
            conexao.CloseConect();
        }
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void spnTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spnTipoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_spnTipoActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        conexao.OpenConect();
        conexao.Delete("DELETE FROM TAB_PRODUTOEXTRAS WHERE CODPRODUTO="+txtCodigo.getText());
        conexao.Delete("DELETE FROM TAB_PRODUTOINGREDIENTES WHERE CODPRODUTO="+txtCodigo.getText());
        conexao.Delete("DELETE FROM TAB_PRODUTOS WHERE CODPRODUTO="+txtCodigo.getText());
        limparTela();
        JOptionPane.showMessageDialog(null, "Produto excluido com sucesso!", "Atenção!", 1);       
        conexao.CloseConect();
    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnVizualizarImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVizualizarImagemActionPerformed
        if (!txtCaminhoFoto.getText().equals("")){
            try {
                conexao.OpenConect();
                conexao.Select("SELECT FOTO FROM TAB_PRODUTOS WHERE CODPRODUTO="+txtCodigo.getText());
                if (conexao.rs.next()){
                    Blob blob = conexao.rs.getBlob("FOTO");
                    FrmVerImagem vImagem = new FrmVerImagem();
                    ImageIcon imageIcon = new ImageIcon(blob.getBytes(1, (int)blob.length()));
                    vImagem.lblImagem.setIcon(imageIcon);
                    vImagem.setVisible(true);   
                }
            } catch (SQLException ex) {
                System.out.println("Erro: "+ex.getMessage());
            }
        }else{
            JOptionPane.showMessageDialog(null, "Selecione o produto.\nCaso esteja cadastrando é necessario que salve primeiramente!", "Atenção!", 0);                  
        }
    }//GEN-LAST:event_btnVizualizarImagemActionPerformed
 
    public void limparTela(){
        txtCodigo.setText("");
        txtNomeProduto.setText("");
        txtPreco.setText("");
        txtTempo.setText("");
        txtDescricao.setText("");
        txtCodSubgrupo.setText("");
        txtSubgrupo.setText("");
        txtGrupo.setText("");
        txtCodIngredientes.setText("");
        txtDesIngredientes.setText("");
        txtCodExtras.setText("");
        txtDesExtras.setText("");
        txtCaminhoFoto.setText("");
        limparTabela(tabIngredientes);
        limparTabela(tabExtras);
    }
    
    public void limparTabela(javax.swing.JTable tabela){  
        DefaultTableModel modelo = (DefaultTableModel) tabela.getModel(); 
        if(tabela.getRowCount()>0){
            int i=0;
            int contColunas=modelo.getRowCount();
            while(i<contColunas){
                modelo.removeRow(0);
                i++; 
            }
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdicionarExtras;
    private javax.swing.JButton btnAdicionarIngre;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnPesquisaFoto;
    private javax.swing.JButton btnPesquisarExtras;
    private javax.swing.JButton btnPesquisarSubgrupo;
    private javax.swing.JButton btnPesuisaIngredientes;
    private javax.swing.JButton btnProcurar;
    private javax.swing.JButton btnRemoverExtras;
    private javax.swing.JButton btnRemoverIngre;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JButton btnVizualizarImagem;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JComboBox spnTipo;
    private javax.swing.JTable tabExtras;
    private javax.swing.JTable tabIngredientes;
    private javax.swing.JTextField txtCaminhoFoto;
    private javax.swing.JTextField txtCodExtras;
    private javax.swing.JTextField txtCodIngredientes;
    private javax.swing.JTextField txtCodSubgrupo;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtDesExtras;
    private javax.swing.JTextField txtDesIngredientes;
    private javax.swing.JTextArea txtDescricao;
    private javax.swing.JTextField txtGrupo;
    private javax.swing.JTextField txtNomeProduto;
    private javax.swing.JFormattedTextField txtPreco;
    private javax.swing.JTextField txtSubgrupo;
    private javax.swing.JFormattedTextField txtTempo;
    // End of variables declaration//GEN-END:variables
}
